package com.cungmua.app.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Joiner;

import java.io.Serializable;
import java.util.List;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class ShippingAddress implements Serializable {
    private int id;
    private String customerName;
    private String phone;
    private String houseNumber;
    private String streetName;
    private String buildingName;
    private String cityName;
    private String districtName;
    private String wardName;
    private int addressType;
    private boolean defaultAddress;
    private List<PaymentType> paymentList;

    private int cityId;
    private int districtId;
    private int wardId;

    @JsonProperty("Id")
    public void setId(int id) {
        this.id = id;
    }

    @JsonProperty("CustomerName")
    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    @JsonProperty("Phone")
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @JsonProperty("HouseNumber")
    public void setHouseNumber(String houseNumber) {
        this.houseNumber = houseNumber;
    }

    @JsonProperty("StreetName")
    public void setStreetName(String streetName) {
        this.streetName = streetName;
    }

    @JsonProperty("BuildingName")
    public void setBuildingName(String buildingName) {
        this.buildingName = buildingName;
    }

    @JsonProperty("CityName")
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    @JsonProperty("DistrictName")
    public void setDistrictName(String districtName) {
        this.districtName = districtName;
    }

    @JsonProperty("WardName")
    public void setWardName(String wardName) {
        this.wardName = wardName;
    }

    @JsonProperty("AddressType")
    public void setAddressType(int addressType) {
        this.addressType = addressType;
    }

    @JsonProperty("IsDefault")
    public void setDefaultAddress(boolean defaultAddress) {
        this.defaultAddress = defaultAddress;
    }

    @JsonProperty("PaymentList")
    public void setPaymentList(List<PaymentType> paymentList) {
        this.paymentList = paymentList;
    }

    @JsonIgnore
    public void setAddressId(int addressId) {
        this.id = addressId;
    }

    @JsonIgnore
    public void setCityId(int cityId) {
        this.cityId = cityId;
    }

    @JsonIgnore
    public void setDistrictId(int districtId) {
        this.districtId = districtId;
    }

    @JsonIgnore
    public void setWardId(int wardId) {
        this.wardId = wardId;
    }

    @JsonIgnore
    public int getId() {
        return id;
    }

    @JsonIgnore
    public String getCustomerName() {
        return customerName;
    }

    @JsonProperty("ReceiverName")
    public String getReceiverName() {
        return customerName;
    }

    @JsonProperty("Phone")
    public String getPhone() {
        return phone;
    }

    @JsonProperty("HouseNumber")
    public String getHouseNumber() {
        return houseNumber;
    }

    @JsonProperty("StreetName")
    public String getStreetName() {
        return streetName;
    }

    @JsonProperty("BuildingName")
    public String getBuildingName() {
        return buildingName;
    }

    @JsonIgnore
    public String getCityName() {
        return cityName;
    }

    @JsonIgnore
    public String getDistrictName() {
        return districtName;
    }

    @JsonIgnore
    public String getWardName() {
        return wardName;
    }

    @JsonIgnore
    public boolean isDefaultAddress() {
        return defaultAddress;
    }

    @JsonIgnore
    public List<PaymentType> getPaymentList() {
        return paymentList;
    }

    @JsonProperty("CityId")
    public int getCityId() {
        return cityId;
    }

    @JsonProperty("DistrictId")
    public int getDistrictId() {
        return districtId;
    }

    @JsonProperty("WardId")
    public int getWardId() {
        return wardId;
    }

    @JsonProperty("AddressType")
    public int getAddressType() {
        return addressType;
    }

    @JsonProperty("AddressId")
    public int getAddressId() {
        return id;
    }

    @JsonIgnore
    public String getAddressString() {
        if (getBuildingName().equals("")) {
            String[] strings = new String[] {getHouseNumber(), getStreetName(),
                    getWardName(),  getDistrictName(), getCityName(),
            };
            return Joiner.on(", ").skipNulls().join(strings);
        } else {
            String[] strings = new String[] {
                    getBuildingName(), getHouseNumber(), getStreetName(),
                    getWardName(),  getDistrictName(), getCityName(),
            };
            return Joiner.on(", ").skipNulls().join(strings);
        }
    }
}
